<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>主题案例分类添加</title>
    <link rel="shortcut icon" href="/images/index/logo.ico">
    <style>
        .refresh, .search {
            display: inline-block;
            float: right;
        }

        .search {
            margin-right: 40%;
            cursor: pointer;
        }
    </style>
</head>
<body>
<div class="refresh">
    <button class="btn btn-info refresh" title="刷新" data-url="/themeClass/admin/list"><span
            class="glyphicon glyphicon-refresh"></span></button>
</div>
<div class="">
    <ol class="breadcrumb">
        <li><a href="javascript:;">主题案例管理</a></li>
        <li class="active">案例管理</li>
    </ol>
</div>
<div class="list_show">
    <table class="table table-bordered table-responsive">
        <tr>
            <th>id</th>
            <th>名称</th>
            <th>介绍</th>
            <th>时间</th>
            <th>操作</th>
        </tr>
        <c:forEach var="data" items="${dataMap}">

            <tr>
                <th class="id">${data.id}</th>
                <th><p contenteditable="true">${data.name}</p></th>
                <th>${data.content}</th>
                <th>${data.date}</th>
                <th>
                    <button class="btn btn-danger delete">删除</button>
                </th>
            </tr>
        </c:forEach>

    </table>
    <button class="btn btn-info add" data-url="/themeClass/admin/addThemeClass">
        <span class="glyphicon glyphicon-plus"></span> 添加
    </button>

</div>
<script>
    $(document).ready(function () {
        $('.refresh').click(function () {
            var scope = $(this);
            $('.content_right').load(scope.attr('data-url'));
            toast_text('刷新成功', 2000);
        });
        //即时修改
        $('p').blur(function () {
            var id = $(this).parent().prev().text();
            var text = $(this).text();
            $.post('/themeClass/admin/changeThemeClass', {id: id, name: text}, function (data) {
                toast_text(data.msg, 2000);
            });
        });
        //删除操作
        $('.delete').click(function () {
            var scope = $(this);
            var id = $(this).parent().siblings('.id').text();
            custom_modal('你确定要删除么？');
            $('.modal_footer button').eq(0).unbind().click(function () {
                $.post("/themeClass/admin/delete", {id: id}, function (data) {
                    if (data.code == 200) {
                        scope.parents('tr').remove();
                    }
                    $('.modal_1').fadeOut();
                    toast_text(data.msg, 600);
                })
            });

        });
        $('.add').click(function () {
            var scope = $(this);
            $('.content_right').load(scope.attr('data-url'));
        });
    });
</script>
</body>
</html>